package com.whxd.framework.security;

import java.util.Collection;
import java.util.Date;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

/**
 * 用户登录信息
 * 
 * @author 张世鹏
 * @since 2013-6-13
 */
public class FrameworkUserDetails extends User {

	private static final long serialVersionUID = 1L;

	private Long id;// 某个用户在当前应用的id，应用内唯一

	private String casId;// 整个cas生态圈的用户id，生态圈唯一

	private String sex;

	private String email;

	private String address;

	private Integer age;

	private String realName;

	private String mobile;

	public FrameworkUserDetails(Long id, String casId, String username, String sex, String email, String address,
			Integer age, String realName, String password, String mobile, boolean enabled, boolean accountNonExpired,
			boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
		super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
		this.id = id;
		this.casId = casId;
		this.sex = sex;
		this.email = email;
		this.address = address;
		this.age = age;
		this.realName = realName;
		this.mobile = mobile;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCasId() {
		return casId;
	}

	public void setCasId(String casId) {
		this.casId = casId;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	// public Date getLoginTime() {
	// return loginTime;
	// }
	//
	// public void setLoginTime(Date loginTime) {
	// this.loginTime = loginTime;
	// }

	/** * 获取当前登录用户详细信息必须重写次方法 */
	public int hashCode() {
		return getUsername().hashCode();
	}

	/** * 获取当前登录用户详细信息必须重写次方法 */
	public boolean equals(Object obj) {
		if (obj instanceof FrameworkUserDetails) {
			FrameworkUserDetails ud = (FrameworkUserDetails) obj;
			if (ud.getCasId().equals(this.getCasId())) {
				return true;
			}
		}
		return false;
	}
}
